<template>
  <div class="main" ref="main" style="width: 600px; height: 300px"></div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "ClassFy",
  props: ["shuju"],
  data() {
    return {
      datas: [],
    };
  },
  watch: {
    shuju: {
      deep: true,
      // immediate: true,
      handler(value) {
        // console.log(value[2]);
        let label = value[2].label;
        let values = value[2].value;
        this.datas = label.map((item, index) => {
          // console.log(item);
          return [item, values[index]];
        });
        // console.log(this.datas);
        this.into();
      },
    },
  },
  created() {
    this.$nextTick(() => {
      this.into();
    });
  },
  methods: {
    into() {
      var option = {
        title: {
          text: "设备分类汇总",

          left: "right",
          link: "https://www.baidu.com",
          target: "self",
          textStyle: {
            fontSize: 38,
            color: "rgba(0, 255, 13, 1)",
            fontFamily: "Courier New",
            lineHeight: 40,
            width: 134,
            height: 26,
            textBorderColor: "rgba(49, 9, 210, 0.94)",
            textBorderWidth: 5.5,
            textBorderType: "dotted",
            textBorderDashOffset: 27,
            textShadowColor: "rgba(7, 217, 232, 1)",
            textShadowBlur: 11,
            textShadowOffsetX: 13.5,
            textShadowOffsetY: 6.5,
          },
        },
        dataset: [
          {
            dimensions: ["name", "score"],
            source: this.datas,
            // [
            //   ["Hannah Krause", 314],
            //   ["Zhao Qian", 351],
            //   ["Jasmin Krause ", 287],
            //   ["Li Lei", 219],
            //   ["Karle Neumann", 253],
            //   ["Adrian Groß", 230],
            //   ["Mia Neumann", 165],
            //   ["Böhm Fuchs", 318],
            //   ["Han Meimei", 366],
            // ],
          },
          {
            transform: {
              type: "sort",
              config: { dimension: "score", order: "desc" },
            },
          },
        ],
        xAxis: {
          type: "category",
          axisLabel: { interval: 0, rotate: 30 },
        },
        yAxis: {},
        series: {
          type: "bar",
          encode: { x: "name", y: "score" },
          datasetIndex: 1,
        },
      };
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(this.$refs["main"]);
      // console.log(myChart);
      // 绘制图表
      myChart.setOption(option);
    },
  },
};
</script>

<style scoped lang="less">
.main {
  background: #f3f3f3;
  border-radius: 20px;
  padding-top: 50px;
  margin-left: 30px;
}
</style>